package com.wpen.unit.service.system.impl;

import java.util.List;

import com.wpen.unit.service.system.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wpen.unit.cvt.system.NoticeCvt;
import com.wpen.unit.infra.mybatis.system.po.NoticePo;
import com.wpen.unit.infra.repository.system.NoticeRepository;
import com.wpen.unit.web.dto.system.NoticeListRequest;
import com.wpen.unit.web.dto.system.NoticeListResponse;
import com.wpen.unit.web.dto.system.NoticeListRowsResponse;

/**
 * sys_notice业务处理.
 * 
 * @author Wang Peng
 * @date 2023-02-26
 */
@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeRepository noticeRepository;

    @Override
    public NoticeListResponse queryListNotice(NoticeListRequest noticeListRequest){
        int index = noticeListRequest.getIndex();
    	int size = noticeListRequest.getSize();
        // 数据库查询
        NoticePo noticePo = NoticeCvt.INSTANCE.queryListDto2Do(noticeListRequest);

        long total = noticeRepository.count(noticePo);
        List<NoticePo> noticePoLists = noticeRepository.queryList(index, size,noticePo);

        // 返回响应信息
        NoticeListResponse noticeListResponse = new NoticeListResponse();
        noticeListResponse.setTotal(total);
		noticeListResponse.setCount(0);
        if (noticePoLists != null) {
            noticeListResponse.setCount(noticePoLists.size());
            List<NoticeListRowsResponse> listRows = noticeListResponse.getRows();
            for (NoticePo inNoticePo : noticePoLists) {
                NoticeListRowsResponse row = NoticeCvt.INSTANCE.queryListRowDo2Dto(inNoticePo);
                listRows.add(row);
            }
            noticeListResponse.setRows(listRows);
        }

        return noticeListResponse;
    }

}
